/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package behaviourdiagram.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.InternalEList;

import behaviourdiagram.Behaviour;
import behaviourdiagram.BehaviourInput;
import behaviourdiagram.BehaviourOutput;
import behaviourdiagram.BehaviourState;
import behaviourdiagram.BehaviourdiagramPackage;
import fsm.FSM;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Behaviour</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link behaviourdiagram.impl.BehaviourImpl#getName <em>Name</em>}</li>
 *   <li>{@link behaviourdiagram.impl.BehaviourImpl#getPriority <em>Priority</em>}</li>
 *   <li>{@link behaviourdiagram.impl.BehaviourImpl#getRepresentedBy <em>Represented By</em>}</li>
 *   <li>{@link behaviourdiagram.impl.BehaviourImpl#getState <em>State</em>}</li>
 *   <li>{@link behaviourdiagram.impl.BehaviourImpl#getInputs <em>Inputs</em>}</li>
 *   <li>{@link behaviourdiagram.impl.BehaviourImpl#getOutputs <em>Outputs</em>}</li>
 *   <li>{@link behaviourdiagram.impl.BehaviourImpl#getInputCondition <em>Input Condition</em>}</li>
 *   <li>{@link behaviourdiagram.impl.BehaviourImpl#getOutputCondition <em>Output Condition</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class BehaviourImpl extends EObjectImpl implements Behaviour {
	/**
   * The default value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
	protected static final String NAME_EDEFAULT = null;

	/**
   * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
	protected String name = NAME_EDEFAULT;

	/**
   * The default value of the '{@link #getPriority() <em>Priority</em>}' attribute.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getPriority()
   * @generated
   * @ordered
   */
	protected static final int PRIORITY_EDEFAULT = 0;

	/**
   * The cached value of the '{@link #getPriority() <em>Priority</em>}' attribute.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getPriority()
   * @generated
   * @ordered
   */
	protected int priority = PRIORITY_EDEFAULT;

	/**
   * The cached value of the '{@link #getRepresentedBy() <em>Represented By</em>}' reference.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getRepresentedBy()
   * @generated
   * @ordered
   */
	protected FSM representedBy;

  /**
   * The cached value of the '{@link #getState() <em>State</em>}' containment reference.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getState()
   * @generated
   * @ordered
   */
	protected BehaviourState state;

  /**
   * The cached value of the '{@link #getInputs() <em>Inputs</em>}' containment reference list.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getInputs()
   * @generated
   * @ordered
   */
	protected EList<BehaviourInput> inputs;

  /**
   * The cached value of the '{@link #getOutputs() <em>Outputs</em>}' containment reference list.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getOutputs()
   * @generated
   * @ordered
   */
	protected EList<BehaviourOutput> outputs;

  /**
   * The default value of the '{@link #getInputCondition() <em>Input Condition</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getInputCondition()
   * @generated
   * @ordered
   */
  protected static final String INPUT_CONDITION_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getInputCondition() <em>Input Condition</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getInputCondition()
   * @generated
   * @ordered
   */
  protected String inputCondition = INPUT_CONDITION_EDEFAULT;

  /**
   * The default value of the '{@link #getOutputCondition() <em>Output Condition</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getOutputCondition()
   * @generated
   * @ordered
   */
  protected static final String OUTPUT_CONDITION_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getOutputCondition() <em>Output Condition</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getOutputCondition()
   * @generated
   * @ordered
   */
  protected String outputCondition = OUTPUT_CONDITION_EDEFAULT;

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	protected BehaviourImpl() {
    super();
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	protected EClass eStaticClass() {
    return BehaviourdiagramPackage.Literals.BEHAVIOUR;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public String getName() {
    return name;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setName(String newName) {
    String oldName = name;
    name = newName;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, BehaviourdiagramPackage.BEHAVIOUR__NAME, oldName, name));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public int getPriority() {
    return priority;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setPriority(int newPriority) {
    int oldPriority = priority;
    priority = newPriority;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, BehaviourdiagramPackage.BEHAVIOUR__PRIORITY, oldPriority, priority));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public FSM getRepresentedBy() {
    if (representedBy != null && representedBy.eIsProxy())
    {
      InternalEObject oldRepresentedBy = (InternalEObject)representedBy;
      representedBy = (FSM)eResolveProxy(oldRepresentedBy);
      if (representedBy != oldRepresentedBy)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, BehaviourdiagramPackage.BEHAVIOUR__REPRESENTED_BY, oldRepresentedBy, representedBy));
      }
    }
    return representedBy;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public FSM basicGetRepresentedBy() {
    return representedBy;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setRepresentedBy(FSM newRepresentedBy) {
    FSM oldRepresentedBy = representedBy;
    representedBy = newRepresentedBy;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, BehaviourdiagramPackage.BEHAVIOUR__REPRESENTED_BY, oldRepresentedBy, representedBy));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public BehaviourState getState() {
    return state;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public NotificationChain basicSetState(BehaviourState newState, NotificationChain msgs) {
    BehaviourState oldState = state;
    state = newState;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, BehaviourdiagramPackage.BEHAVIOUR__STATE, oldState, newState);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setState(BehaviourState newState) {
    if (newState != state)
    {
      NotificationChain msgs = null;
      if (state != null)
        msgs = ((InternalEObject)state).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - BehaviourdiagramPackage.BEHAVIOUR__STATE, null, msgs);
      if (newState != null)
        msgs = ((InternalEObject)newState).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - BehaviourdiagramPackage.BEHAVIOUR__STATE, null, msgs);
      msgs = basicSetState(newState, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, BehaviourdiagramPackage.BEHAVIOUR__STATE, newState, newState));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public EList<BehaviourInput> getInputs() {
    if (inputs == null)
    {
      inputs = new EObjectContainmentWithInverseEList<BehaviourInput>(BehaviourInput.class, this, BehaviourdiagramPackage.BEHAVIOUR__INPUTS, BehaviourdiagramPackage.BEHAVIOUR_INPUT__BEHAVIOUR);
    }
    return inputs;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public EList<BehaviourOutput> getOutputs() {
    if (outputs == null)
    {
      outputs = new EObjectContainmentWithInverseEList<BehaviourOutput>(BehaviourOutput.class, this, BehaviourdiagramPackage.BEHAVIOUR__OUTPUTS, BehaviourdiagramPackage.BEHAVIOUR_OUTPUT__BEHAVIOUR);
    }
    return outputs;
  }

	/**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getInputCondition()
  {
    return inputCondition;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setInputCondition(String newInputCondition)
  {
    String oldInputCondition = inputCondition;
    inputCondition = newInputCondition;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, BehaviourdiagramPackage.BEHAVIOUR__INPUT_CONDITION, oldInputCondition, inputCondition));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getOutputCondition()
  {
    return outputCondition;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setOutputCondition(String newOutputCondition)
  {
    String oldOutputCondition = outputCondition;
    outputCondition = newOutputCondition;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, BehaviourdiagramPackage.BEHAVIOUR__OUTPUT_CONDITION, oldOutputCondition, outputCondition));
  }

  /**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
    switch (featureID)
    {
      case BehaviourdiagramPackage.BEHAVIOUR__INPUTS:
        return ((InternalEList<InternalEObject>)(InternalEList<?>)getInputs()).basicAdd(otherEnd, msgs);
      case BehaviourdiagramPackage.BEHAVIOUR__OUTPUTS:
        return ((InternalEList<InternalEObject>)(InternalEList<?>)getOutputs()).basicAdd(otherEnd, msgs);
    }
    return super.eInverseAdd(otherEnd, featureID, msgs);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
    switch (featureID)
    {
      case BehaviourdiagramPackage.BEHAVIOUR__STATE:
        return basicSetState(null, msgs);
      case BehaviourdiagramPackage.BEHAVIOUR__INPUTS:
        return ((InternalEList<?>)getInputs()).basicRemove(otherEnd, msgs);
      case BehaviourdiagramPackage.BEHAVIOUR__OUTPUTS:
        return ((InternalEList<?>)getOutputs()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
    switch (featureID)
    {
      case BehaviourdiagramPackage.BEHAVIOUR__NAME:
        return getName();
      case BehaviourdiagramPackage.BEHAVIOUR__PRIORITY:
        return getPriority();
      case BehaviourdiagramPackage.BEHAVIOUR__REPRESENTED_BY:
        if (resolve) return getRepresentedBy();
        return basicGetRepresentedBy();
      case BehaviourdiagramPackage.BEHAVIOUR__STATE:
        return getState();
      case BehaviourdiagramPackage.BEHAVIOUR__INPUTS:
        return getInputs();
      case BehaviourdiagramPackage.BEHAVIOUR__OUTPUTS:
        return getOutputs();
      case BehaviourdiagramPackage.BEHAVIOUR__INPUT_CONDITION:
        return getInputCondition();
      case BehaviourdiagramPackage.BEHAVIOUR__OUTPUT_CONDITION:
        return getOutputCondition();
    }
    return super.eGet(featureID, resolve, coreType);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
    switch (featureID)
    {
      case BehaviourdiagramPackage.BEHAVIOUR__NAME:
        setName((String)newValue);
        return;
      case BehaviourdiagramPackage.BEHAVIOUR__PRIORITY:
        setPriority((Integer)newValue);
        return;
      case BehaviourdiagramPackage.BEHAVIOUR__REPRESENTED_BY:
        setRepresentedBy((FSM)newValue);
        return;
      case BehaviourdiagramPackage.BEHAVIOUR__STATE:
        setState((BehaviourState)newValue);
        return;
      case BehaviourdiagramPackage.BEHAVIOUR__INPUTS:
        getInputs().clear();
        getInputs().addAll((Collection<? extends BehaviourInput>)newValue);
        return;
      case BehaviourdiagramPackage.BEHAVIOUR__OUTPUTS:
        getOutputs().clear();
        getOutputs().addAll((Collection<? extends BehaviourOutput>)newValue);
        return;
      case BehaviourdiagramPackage.BEHAVIOUR__INPUT_CONDITION:
        setInputCondition((String)newValue);
        return;
      case BehaviourdiagramPackage.BEHAVIOUR__OUTPUT_CONDITION:
        setOutputCondition((String)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public void eUnset(int featureID) {
    switch (featureID)
    {
      case BehaviourdiagramPackage.BEHAVIOUR__NAME:
        setName(NAME_EDEFAULT);
        return;
      case BehaviourdiagramPackage.BEHAVIOUR__PRIORITY:
        setPriority(PRIORITY_EDEFAULT);
        return;
      case BehaviourdiagramPackage.BEHAVIOUR__REPRESENTED_BY:
        setRepresentedBy((FSM)null);
        return;
      case BehaviourdiagramPackage.BEHAVIOUR__STATE:
        setState((BehaviourState)null);
        return;
      case BehaviourdiagramPackage.BEHAVIOUR__INPUTS:
        getInputs().clear();
        return;
      case BehaviourdiagramPackage.BEHAVIOUR__OUTPUTS:
        getOutputs().clear();
        return;
      case BehaviourdiagramPackage.BEHAVIOUR__INPUT_CONDITION:
        setInputCondition(INPUT_CONDITION_EDEFAULT);
        return;
      case BehaviourdiagramPackage.BEHAVIOUR__OUTPUT_CONDITION:
        setOutputCondition(OUTPUT_CONDITION_EDEFAULT);
        return;
    }
    super.eUnset(featureID);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public boolean eIsSet(int featureID) {
    switch (featureID)
    {
      case BehaviourdiagramPackage.BEHAVIOUR__NAME:
        return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
      case BehaviourdiagramPackage.BEHAVIOUR__PRIORITY:
        return priority != PRIORITY_EDEFAULT;
      case BehaviourdiagramPackage.BEHAVIOUR__REPRESENTED_BY:
        return representedBy != null;
      case BehaviourdiagramPackage.BEHAVIOUR__STATE:
        return state != null;
      case BehaviourdiagramPackage.BEHAVIOUR__INPUTS:
        return inputs != null && !inputs.isEmpty();
      case BehaviourdiagramPackage.BEHAVIOUR__OUTPUTS:
        return outputs != null && !outputs.isEmpty();
      case BehaviourdiagramPackage.BEHAVIOUR__INPUT_CONDITION:
        return INPUT_CONDITION_EDEFAULT == null ? inputCondition != null : !INPUT_CONDITION_EDEFAULT.equals(inputCondition);
      case BehaviourdiagramPackage.BEHAVIOUR__OUTPUT_CONDITION:
        return OUTPUT_CONDITION_EDEFAULT == null ? outputCondition != null : !OUTPUT_CONDITION_EDEFAULT.equals(outputCondition);
    }
    return super.eIsSet(featureID);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public String toString() {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (name: ");
    result.append(name);
    result.append(", priority: ");
    result.append(priority);
    result.append(", inputCondition: ");
    result.append(inputCondition);
    result.append(", outputCondition: ");
    result.append(outputCondition);
    result.append(')');
    return result.toString();
  }

} //BehaviourImpl
